function Node(value){
    this.val = value;
    this.left = null;
    this.right = null;
}

var a = new Node("a");
var b = new Node("b");
var c = new Node("c");
var d = new Node("d");
var e = new Node("e");
var f = new Node("f");
var a2 = new Node("a");
a.left = b;
a.right = c;
b.left = d;
b.right = e;
d.left = f;
function does(pRoot1,pRoot2){
    if(pRoot2 == null) return true;
    if(pRoot1 == null) return false;
    if(pRoot1.val != pRoot2.val) return false;
    return does(pRoot1.left, pRoot2.left) && does(pRoot1.right, pRoot2.right);
}
function HasSubtree(pRoot1, pRoot2)
{
    // write code here
    var result = false;
    if(pRoot1!=null && pRoot2!=null) {
        if (pRoot1.val == pRoot2.val)
            result = does(pRoot1, pRoot2);
        if (!result) {
            result = HasSubtree(pRoot1.left, pRoot2);
        }
        if (!result) {
            result = HasSubtree(pRoot1.right, pRoot2);
        }
    }
    return result;
}

console.log(HasSubtree(a,a2));